
//思想：动态规划

public class Main{
     public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] array = new int[n];
         for(int i = 0; i < array.length; i++){
             array[i] = sc.nextInt();
         }

         int sum = array[0];  //记录子序列和
         int max = array[0];  //表示子序列的最大和
         for(int i = 1; i < n; i++){
             sum = sum+array[i] > array[i] ? sum+array[i] : array[i];
             if(sum >= max){
                 max = sum;
             }
         }
         System.out.println(max);
     }
}


//========================================


public class Main{
     public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] array = new int[n];
         for(int i = 0; i < array.length; i++){
             array[i] = sc.nextInt();
         }

         int sum = array[0];  //记录子序列和
         int max = array[0]； //记录子序列最大和
         for(int i = 1; i < n; i++){
             if(sum < 0){
                 sum = array[i];
             }else{
                 sum += array[i];
             }

             if(sum >= max){
                 max = sum;
             }
         }
         System.out.println(max);
     }
}